package win.larryzeal.spring.jmx.client.jmxclientdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jmx.access.MBeanProxyFactoryBean;
import win.larryzeal.spring.jmx.client.jmxclientdemo.service.MyManagedInterfaces;

import javax.management.MalformedObjectNameException;
import java.net.MalformedURLException;

/**
 * Created by 张少昆 on 2017/8/23 0023.
 */
@Configuration
public class JmxClientConfig {

	@Bean("proxy")
	public MBeanProxyFactoryBean mBeanProxyFactoryBean() throws MalformedURLException, MalformedObjectNameException{
		MBeanProxyFactoryBean mBeanProxyFactoryBean = new MBeanProxyFactoryBean();

		mBeanProxyFactoryBean.setServiceUrl("service:jmx:rmi://localhost/jndi/rmi://localhost:1099/test");
		mBeanProxyFactoryBean.setObjectName("win.larryzeal.spring.jmx.server.jmxserverdemo.service:type=Service,name=MyJavaObject");

		mBeanProxyFactoryBean.setConnectOnStartup(true);
		mBeanProxyFactoryBean.setProxyInterface(MyManagedInterfaces.class);

		return mBeanProxyFactoryBean;
	}
}
